<?php 
namespace app\common\model;
class OrderAmount extends Common{
	protected $insert = ['dateline'=>SYS_TIME];
	public function pay_success($ordersn){
		$info = $this->where('ordersn', $ordersn)->find();
		if($info['status'] >= 1) return false;
		model("MemberAmountLog")->add($info, 1);
		return $this->where('ordersn', $ordersn)->update(['status'=>1, 'paytime'=>SYS_TIME]);
	}
	protected function getNicknameAttr($value, $data){
		$info = model("Member")->get_data(['item_id'=>$data['userid']]);
		return $info['nickname'];
	}
	protected function getStatusAttr($value){
		$arr = [0=>'正在充值', 1=>'充值成功', 2=>'充值失败'];
		return $arr[$value];
	}
	protected function getPaynameAttr($value, $data){
		return config('PAYTYPE.'.$data['paytype']);
	}
	protected function getDatelineAttr($value){
		return date('Y-m-d H:i:s', $value);
	}
	protected function getPaytimeAttr($value){
		return $value ? date('Y-m-d H:i:s', $value) : '未完成';
	}
	public function save_datas($data){
		$data['ordersn'] = 'amount'.date('YmdHis',SYS_TIME).rand(1000, 9999);
		$data['description'] = config('PAYTYPE.'.$data['paytype']).'充值';
		$id = model("Order")->save_data($data);
		if (!$id) {
			return ['订单提交失败', []];
		}
		$data['price'] = $data['totalprice'];
		$ids = $this->save_data($data);
		if (!$ids) {
			return ['订单提交失败', []];
		}
		return [true, ['paytype'=>$data['paytype'],'ordersn'=>$data['ordersn'],'ordername'=>$data['description'],'totalprice'=>$data['totalprice']]];
	}
}	